using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region BusinessPurpose

	/// <summary>
	/// BusinessPurpose object for NHibernate mapped table 'BusinessPurpose'.
	/// </summary>
	[Serializable]
	public class BusinessPurpose : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected bool _isInSalesContract;
		protected bool _isContractSigned;
		protected bool _recreationalActivity;
		protected bool _isNeedInvitationLetter;
		protected string _opportunities;
		protected string _itinerary;
		protected Application _application;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public BusinessPurpose() { }

		public BusinessPurpose( bool isInSalesContract, bool isContractSigned, bool recreationalActivity, bool isNeedInvitationLetter, string opportunities, string itinerary, Application application )
		{
			this._isInSalesContract = isInSalesContract;
			this._isContractSigned = isContractSigned;
			this._recreationalActivity = recreationalActivity;
			this._isNeedInvitationLetter = isNeedInvitationLetter;
			this._opportunities = opportunities;
			this._itinerary = itinerary;
			this._application = application;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public bool IsInSalesContract
		{
			get { return _isInSalesContract; }
			set { _isInSalesContract = value; }
		}

		public bool IsContractSigned
		{
			get { return _isContractSigned; }
			set { _isContractSigned = value; }
		}

		public bool RecreationalActivity
		{
			get { return _recreationalActivity; }
			set { _recreationalActivity = value; }
		}

		public bool IsNeedInvitationLetter
		{
			get { return _isNeedInvitationLetter; }
			set { _isNeedInvitationLetter = value; }
		}

		public string Opportunities
		{
			get { return _opportunities; }
			set
			{
				if ( value != null && value.Length > 500)
					value = value.Substring(0, 500 );
				_opportunities = value;
			}
		}

		public string Itinerary
		{
			get { return _itinerary; }
			set
			{
				if ( value != null && value.Length > 250)
					value = value.Substring(0, 250 );
				_itinerary = value;
			}
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is BusinessPurpose))
				throw new InvalidCastException("This object is not of type BusinessPurpose");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((BusinessPurpose)obj).Id);
					break;
				case "IsInSalesContract":
					relativeValue = this.IsInSalesContract.CompareTo(((BusinessPurpose)obj).IsInSalesContract);
					break;
				case "IsContractSigned":
					relativeValue = this.IsContractSigned.CompareTo(((BusinessPurpose)obj).IsContractSigned);
					break;
				case "RecreationalActivity":
					relativeValue = this.RecreationalActivity.CompareTo(((BusinessPurpose)obj).RecreationalActivity);
					break;
				case "IsNeedInvitationLetter":
					relativeValue = this.IsNeedInvitationLetter.CompareTo(((BusinessPurpose)obj).IsNeedInvitationLetter);
					break;
				case "Opportunities":
						relativeValue = ( this.Opportunities != null ) ? this.Opportunities.CompareTo(((BusinessPurpose)obj).Opportunities) : -1;
					break;
				case "Itinerary":
						relativeValue = ( this.Itinerary != null ) ? this.Itinerary.CompareTo(((BusinessPurpose)obj).Itinerary) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (BusinessPurpose.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
